=begin pod :kind("Type") :subkind("class") :category("basic")

=TITLE class RatStr

=SUBTITLE Dual value rational number and string

    class RatStr is Allomorph is Rat {}

C<RatStr> is a dual value type, a subclass of both
L«C<Allomorph>|/type/Allomorph», hence L«C<Str>|/type/Str», and
L«C<Rat>|/type/Rat».

See L«C<Allomorph>|/type/Allomorph» for further details.

=begin code
my $rat-str = <42.1>;
say $rat-str.^name;       # OUTPUT: «RatStr␤»

my Rat $rat = $rat-str;   # OK!
my Str $str = $rat-str;   # OK!

# ∈ operator cares about object identity
say 42.1 ∈ <42.1  55  1>; # OUTPUT: «False␤»
=end code

=head1 Methods

=head2 method new

    method new(Rat $i, Str $s)

The constructor requires both the C<Rat> and the C<Str> value, when constructing one
directly the values can be whatever is required:

    my $f = RatStr.new(42.1, "forty two and a bit");
    say +$f; # OUTPUT: «42.1␤»
    say ~$f; # OUTPUT: «"forty two and a bit"␤»

=head2 method Capture

Defined as:

    method Capture(RatStr:D: --> Capture:D)

Equivalent to L«C<Mu.Capture>|/type/Mu#method_Capture».

=head2 method Numeric

Defined as:

    multi method Numeric(RatStr:D: --> Rat:D)
    multi method Numeric(RatStr:U: --> Rat:D)

The C<:D> variant returns the numeric portion of the invocant. The C<:U> variant issues
a warning about using an uninitialized value in numeric context and then returns value C<0.0>.

=head2 method Rat

    method Rat

Returns the C<Rat> value of the C<RatStr>.

=head2 method Real

Defined as:

    multi method Real(Real:D: --> Rat:D)
    multi method Real(Real:U: --> Rat:D)

The C<:D> variant returns the numeric portion of the invocant. The C<:U> variant issues
a warning about using an uninitialized value in numeric context and then returns value C<0.0>.

=head1 Operators

=head2 infix C«===»

    multi sub infix:<===>(RatStr:D $a, RatStr:D $b)

C<RatStr> Value identity operator. Returns C<True> if the C<Rat>
values of C<$a> and C<$b> are L<identical|/routine/===> and their C<Str>
values are also L<identical|/routine/===>. Returns C<False> otherwise.

=end pod

# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6
